package ollama.ai.two.config;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import ollama.ai.two.service.ChatMemoryService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;


/**
 * @Auther:Liu
 * @Testname:ChatMemoryConfig
 * @Date:2025/9/23 11:44
 */
@Configuration
@Slf4j
public class ChatMemoryConfig {
    @Resource
    private OllamaChatModel ollamaChatModel;
    @Resource
    private ChatMemory chatMemory;
    @Lazy
    private String newRole="你是哈利波特，来自霍格沃兹";
    @Bean(name = "ollamaChatClient")
    public ChatClient ClientConfig() {
        // 使用当前设置的角色信息
        log.info("Using role: {}", newRole);
        return ChatClient
                .builder(ollamaChatModel)
                .defaultSystem(newRole)
                .defaultAdvisors(new MessageChatMemoryAdvisor(chatMemory))
                .build();
    }
}
